package cn.java78.springboot.myschool.config;

import cn.java78.springboot.myschool.printer.ColorFulInk;
import cn.java78.springboot.myschool.printer.Printer;
import cn.java78.springboot.myschool.printer.TextPaper;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;
import java.util.Properties;

/**
 * @author oldliu
 * @since 1.0
 */
@Configuration
@EnableScheduling
public class AppConfig {
    @Bean
    public DatabaseIdProvider getDatabaseIdProvider() {
        DatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
        Properties p = new Properties();
        p.setProperty("Oracle", "oracle");
        p.setProperty("MySQL", "mysql");
        databaseIdProvider.setProperties(p);
        return databaseIdProvider;
    }
    //@Bean
    @Scheduled(cron="*/10 * * * * ?")
    public void timer(){
        System.out.println("当前时间是："+new Date());
    }

    @Bean("p1")
    public Printer getPrinter(){
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>构建了打印机p1");
        Printer p=new Printer();
        p.setBrand("惠普炫彩007");
        p.setPrice(1499);
        p.setInk(new ColorFulInk());
        TextPaper paper=new TextPaper();
        paper.setLines(10);
        paper.setWords(12);
        p.setPaper(paper);
        return p;
    }
    @Bean("p2")
    public Printer getPrinter2(){
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>构建了打印机p2");
        Printer p=new Printer();
        p.setBrand("惠普炫彩007");
        p.setPrice(1499);
        p.setInk(new ColorFulInk());
        TextPaper paper=new TextPaper();
        paper.setLines(16);
        paper.setWords(20);
        p.setPaper(paper);
        return p;
    }
}
